<!DOCTYPE HTML>
<html lang="zh-tw" >
    <!-- Start book python基础语言 -->
    <head>
        <!-- head:start -->
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <title>调试 | python基础语言</title>
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <meta name="description" content="">
        <meta name="generator" content="GitBook 2.6.7">
        
        
        <meta name="HandheldFriendly" content="true"/>
        <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
        <meta name="apple-mobile-web-app-capable" content="yes">
        <meta name="apple-mobile-web-app-status-bar-style" content="black">
        <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
        <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
        
    <link rel="stylesheet" href="../gitbook/style.css">
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-splitter/splitter.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-emphasize/plugin.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-highlight/website.css">
        
    
        
        <link rel="stylesheet" href="../gitbook/plugins/gitbook-plugin-fontsettings/website.css">
        
    
    

        
    
    
    <link rel="next" href="../03day/section.5.html" />
    
    
    <link rel="prev" href="../03day/section.4.html" />
    

        <!-- head:end -->
    </head>
    <body>
        <!-- body:start -->
        
    <div class="book"
        data-level="3.9"
        data-chapter-title="调试"
        data-filepath="03day/section.3.md"
        data-basepath=".."
        data-revision="Fri Mar 17 2017 08:48:09 GMT+0800 (CST)"
        data-innerlanguage="">
    

<div class="book-summary">
    <nav role="navigation">
        <ul class="summary">
            
            
            
            

            

            
    
        <li class="chapter " data-level="0" data-path="index.html">
            
                
                    <a href="../index.html">
                
                        <i class="fa fa-check"></i>
                        
                        课程介绍
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1" data-path="01day/index.html">
            
                
                    <a href="../01day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.</b>
                        
                        面向对象进阶
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.1" data-path="01day/section.1.0.html">
            
                
                    <a href="../01day/section.1.0.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.1.</b>
                        
                        元类
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="01day/section.1.1.html">
            
                
                    <a href="../01day/section.1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.2.</b>
                        
                        python是动态语言
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="01day/section.1.3.html">
            
                
                    <a href="../01day/section.1.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.3.</b>
                        
                        __slots__
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="02day/section.4.html">
            
                
                    <a href="../02day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.4.</b>
                        
                        生成器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="02day/section.3.html">
            
                
                    <a href="../02day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.5.</b>
                        
                        迭代器
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="02day/section.1.html">
            
                
                    <a href="../02day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.6.</b>
                        
                        闭包
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="02day/section.2.html">
            
                
                    <a href="../02day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>1.7.</b>
                        
                        装饰器
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2" data-path="02day/index.html">
            
                
                    <a href="../02day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.</b>
                        
                        其他的知识点
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1" data-path="03day/section.0.2.html">
            
                
                    <a href="../03day/section.0.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.1.</b>
                        
                        import导入模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="03day/section.1.1.html">
            
                
                    <a href="../03day/section.1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.2.</b>
                        
                        循环导入
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="03day/section.0.3.html">
            
                
                    <a href="../03day/section.0.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.3.</b>
                        
                        作用域
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="03day/section.2.html">
            
                
                    <a href="../03day/section.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.4.</b>
                        
                        ==、is
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="03day/section.1.html">
            
                
                    <a href="../03day/section.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.5.</b>
                        
                        深拷贝、浅拷贝
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="03day/section.6.html">
            
                
                    <a href="../03day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.6.</b>
                        
                        进制、位运算
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="01day/section.3.html">
            
                
                    <a href="../01day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.7.</b>
                        
                        私有化
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="2.8" data-path="01day/section.3.1.html">
            
                
                    <a href="../01day/section.3.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>2.8.</b>
                        
                        属性property
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3" data-path="03day/index.html">
            
                
                    <a href="../03day/index.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.</b>
                        
                        其他的知识点
                    </a>
            
            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1" data-path="03day/section.0.1.html">
            
                
                    <a href="../03day/section.0.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.1.</b>
                        
                        垃圾回收(一)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="03day/section.0.1.1.html">
            
                
                    <a href="../03day/section.0.1.1.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.2.</b>
                        
                        垃圾回收(二)
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="03day/section.0.1.2.html">
            
                
                    <a href="../03day/section.0.1.2.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.3.</b>
                        
                        垃圾回收(三)-gc模块
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="01day/section.4.html">
            
                
                    <a href="../01day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.4.</b>
                        
                        内建属性
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="01day/section.6.html">
            
                
                    <a href="../01day/section.6.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.5.</b>
                        
                        内建函数
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="01day/section.7.html">
            
                
                    <a href="../01day/section.7.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.6.</b>
                        
                        集合set
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="02day/section.5.html">
            
                
                    <a href="../02day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.7.</b>
                        
                        functools
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.8" data-path="03day/section.4.html">
            
                
                    <a href="../03day/section.4.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.8.</b>
                        
                        模块
                    </a>
            
            
        </li>
    
        <li class="chapter active" data-level="3.9" data-path="03day/section.3.html">
            
                
                    <a href="../03day/section.3.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.9.</b>
                        
                        调试
                    </a>
            
            
        </li>
    
        <li class="chapter " data-level="3.10" data-path="03day/section.5.html">
            
                
                    <a href="../03day/section.5.html">
                
                        <i class="fa fa-check"></i>
                        
                            <b>3.10.</b>
                        
                        编码风格
                    </a>
            
            
        </li>
    

            </ul>
            
        </li>
    


            
            <li class="divider"></li>
            <li>
                <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
                    本書使用 GitBook 釋出
                </a>
            </li>
            
        </ul>
    </nav>
</div>

    <div class="book-body">
        <div class="body-inner">
            <div class="book-header" role="navigation">
    <!-- Actions Left -->
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../" >python基础语言</a>
    </h1>
</div>

            <div class="page-wrapper" tabindex="-1" role="main">
                <div class="page-inner">
                
                
                    <section class="normal" id="section-">
                    
                        <h1 id="&#x8C03;&#x8BD5;">&#x8C03;&#x8BD5;</h1>
<h2 id="pdb">pdb</h2>
<p>pdb&#x662F;&#x57FA;&#x4E8E;&#x547D;&#x4EE4;&#x884C;&#x7684;&#x8C03;&#x8BD5;&#x5DE5;&#x5177;&#xFF0C;&#x975E;&#x5E38;&#x7C7B;&#x4F3C;gnu&#x7684;gdb&#xFF08;&#x8C03;&#x8BD5;c/c++&#xFF09;&#x3002;</p>
<table>
<thead>
<tr>
<th>&#x547D;&#x4EE4;</th>
<th>&#x7B80;&#x5199;&#x547D;&#x4EE4;</th>
<th>&#x4F5C;&#x7528;</th>
</tr>
</thead>
<tbody>
<tr>
<td>break</td>
<td>b</td>
<td>&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;</td>
</tr>
<tr>
<td>continue</td>
<td>c</td>
<td>&#x7EE7;&#x7EED;&#x6267;&#x884C;&#x7A0B;&#x5E8F;</td>
</tr>
<tr>
<td>list</td>
<td>l</td>
<td>&#x67E5;&#x770B;&#x5F53;&#x524D;&#x884C;&#x7684;&#x4EE3;&#x7801;&#x6BB5;</td>
</tr>
<tr>
<td>step</td>
<td>s</td>
<td>&#x8FDB;&#x5165;&#x51FD;&#x6570;</td>
</tr>
<tr>
<td>return</td>
<td>r</td>
<td>&#x6267;&#x884C;&#x4EE3;&#x7801;&#x76F4;&#x5230;&#x4ECE;&#x5F53;&#x524D;&#x51FD;&#x6570;&#x8FD4;&#x56DE;</td>
</tr>
<tr>
<td>quit</td>
<td>q</td>
<td>&#x4E2D;&#x6B62;&#x5E76;&#x9000;&#x51FA;</td>
</tr>
<tr>
<td>next</td>
<td>n</td>
<td>&#x6267;&#x884C;&#x4E0B;&#x4E00;&#x884C;</td>
</tr>
<tr>
<td>print</td>
<td>p</td>
<td>&#x6253;&#x5370;&#x53D8;&#x91CF;&#x7684;&#x503C;</td>
</tr>
<tr>
<td>help</td>
<td>h</td>
<td>&#x5E2E;&#x52A9;</td>
</tr>
<tr>
<td>args</td>
<td>a</td>
<td>&#x67E5;&#x770B;&#x4F20;&#x5165;&#x53C2;&#x6570;</td>
</tr>
<tr>
<td><ENTER></ENTER></td>
<td>&#x56DE;&#x8F66;</td>
<td>&#x91CD;&#x590D;&#x4E0A;&#x4E00;&#x6761;&#x547D;&#x4EE4;</td>
</tr>
<tr>
<td>break</td>
<td>b</td>
<td>&#x663E;&#x793A;&#x6240;&#x6709;&#x65AD;&#x70B9;</td>
</tr>
<tr>
<td>break lineno</td>
<td>b  lineno</td>
<td>&#x5728;&#x6307;&#x5B9A;&#x884C;&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;</td>
</tr>
<tr>
<td>break file:lineno</td>
<td>b file:lineno</td>
<td>&#x5728;&#x6307;&#x5B9A;&#x6587;&#x4EF6;&#x7684;&#x884C;&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;</td>
</tr>
<tr>
<td>clear num</td>
<td></td>
<td>&#x5220;&#x9664;&#x6307;&#x5B9A;&#x65AD;&#x70B9;</td>
</tr>
<tr>
<td>bt</td>
<td></td>
<td>&#x67E5;&#x770B;&#x51FD;&#x6570;&#x8C03;&#x7528;&#x6808;&#x5E27;</td>
</tr>
</tbody>
</table>
<h3 id="&#x6267;&#x884C;&#x65F6;&#x8C03;&#x8BD5;">&#x6267;&#x884C;&#x65F6;&#x8C03;&#x8BD5;</h3>
<p>&#x7A0B;&#x5E8F;&#x542F;&#x52A8;&#xFF0C;&#x505C;&#x6B62;&#x5728;&#x7B2C;&#x4E00;&#x884C;&#x7B49;&#x5F85;&#x5355;&#x6B65;&#x8C03;&#x8BD5;&#x3002;</p>
<pre><code class="lang-shell">python -m pdb some.py
</code></pre>
<h3 id="&#x4EA4;&#x4E92;&#x8C03;&#x8BD5;">&#x4EA4;&#x4E92;&#x8C03;&#x8BD5;</h3>
<p>&#x8FDB;&#x5165;python&#x6216;ipython&#x89E3;&#x91CA;&#x5668;</p>
<pre><code class="lang-shell">import pdb
pdb.run(&apos;testfun(args)&apos;) #&#x6B64;&#x65F6;&#x4F1A;&#x6253;&#x5F00;pdb&#x8C03;&#x8BD5;&#xFF0C;&#x6CE8;&#x610F;&#xFF1A;&#x5148;&#x4F7F;&#x7528;s&#x8DF3;&#x8F6C;&#x5230;&#x8FD9;&#x4E2A;testfun&#x51FD;&#x6570;&#x4E2D;&#xFF0C;&#x7136;&#x540E;&#x5C31;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;l&#x770B;&#x5230;&#x4EE3;&#x7801;&#x4E86;
</code></pre>
<h3 id="&#x7A0B;&#x5E8F;&#x91CC;&#x57CB;&#x70B9;">&#x7A0B;&#x5E8F;&#x91CC;&#x57CB;&#x70B9;</h3>
<p>&#x5F53;&#x7A0B;&#x5E8F;&#x6267;&#x884C;&#x5230;pdb.set_trace() &#x4F4D;&#x7F6E;&#x65F6;&#x505C;&#x4E0B;&#x6765;&#x8C03;&#x8BD5;</p>
<pre><code class="lang-python">&#x4EE3;&#x7801;&#x4E0A;&#x4E0B;&#x6587;
...

<span class="hljs-keyword">import</span> pdb 
pdb.set_trace() 

...
</code></pre>
<h2 id="&#x65E5;&#x5FD7;&#x8C03;&#x8BD5;">&#x65E5;&#x5FD7;&#x8C03;&#x8BD5;</h2>
<h2 id="print&#x5927;&#x6CD5;&#x597D;">print&#x5927;&#x6CD5;&#x597D;</h2>
<hr>
<p>&#x4F7F;&#x7528;pdb&#x8C03;&#x8BD5;&#x7684;5&#x4E2A;demo</p>
<h4 id="demo-1">demo 1</h4>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pdb 
a = <span class="hljs-string">&quot;aaa&quot;</span>
pdb.set_trace()
b = <span class="hljs-string">&quot;bbb&quot;</span>
c = <span class="hljs-string">&quot;ccc&quot;</span>
final = a + b + c 
<span class="hljs-keyword">print</span> final

<span class="hljs-comment">#&#x8C03;&#x8BD5;&#x65B9;&#x6CD5;</span>

<span class="hljs-comment"># &#x300A;1 &#x663E;&#x793A;&#x4EE3;&#x7801;&#x300B;</span>
<span class="hljs-comment"># l----&gt;&#x80FD;&#x591F;&#x663E;&#x793A;&#x5F53;&#x524D;&#x8C03;&#x8BD5;&#x8FC7;&#x7A0B;&#x4E2D;&#x7684;&#x4EE3;&#x7801;&#xFF0C;&#x5176;&#x5B9E;l&#x8868;&#x793A;list&#x5217;&#x51FA;&#x7684;&#x610F;&#x601D;</span>
  <span class="hljs-comment">#&#x5982;&#x4E0B;&#xFF0C;&#x9014;&#x4E2D;&#xFF0C;-&gt; &#x6307;&#x5411;&#x7684;&#x5730;&#x65B9;&#x8868;&#x793A;&#x8981;&#x5C06;&#x8981;&#x6267;&#x884C;&#x7684;&#x4F4D;&#x7F6E;</span>
  <span class="hljs-comment"># 2      a = &quot;aaa&quot;</span>
  <span class="hljs-comment"># 3      pdb.set_trace()</span>
  <span class="hljs-comment"># 4      b = &quot;bbb&quot;</span>
  <span class="hljs-comment"># 5      c = &quot;ccc&quot;</span>
  <span class="hljs-comment"># 6      pdb.set_trace()</span>
  <span class="hljs-comment"># 7  -&gt;    final = a + b + c</span>
  <span class="hljs-comment"># 8      print final</span>

<span class="hljs-comment"># &#x300A;2 &#x6267;&#x884C;&#x4E0B;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#x300B;</span>
<span class="hljs-comment"># n----&gt;&#x80FD;&#x591F;&#x5411;&#x4E0B;&#x6267;&#x884C;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#xFF0C;&#x7136;&#x540E;&#x505C;&#x6B62;&#x8FD0;&#x884C;&#x7B49;&#x5F85;&#x7EE7;&#x7EED;&#x8C03;&#x8BD5; n&#x8868;&#x793A;next&#x7684;&#x610F;&#x601D;</span>

<span class="hljs-comment"># &#x300A;3 &#x67E5;&#x770B;&#x53D8;&#x91CF;&#x7684;&#x503C;&#x300B;</span>
<span class="hljs-comment"># p----&gt;&#x80FD;&#x591F;&#x67E5;&#x770B;&#x53D8;&#x91CF;&#x7684;&#x503C;&#xFF0C;p&#x8868;&#x793A;prit&#x6253;&#x5370;&#x8F93;&#x51FA;&#x7684;&#x610F;&#x601D;</span>
    <span class="hljs-comment">#&#x4F8B;&#x5982;&#xFF1A;</span>
    <span class="hljs-comment"># p name &#x8868;&#x793A;&#x67E5;&#x770B;&#x53D8;&#x91CF;name&#x7684;&#x503C;</span>
</code></pre>
<h4 id="demo-2">demo 2</h4>
<pre><code class="lang-python"><span class="hljs-keyword">import</span> pdb 
a = <span class="hljs-string">&quot;aaa&quot;</span>
pdb.set_trace()
b = <span class="hljs-string">&quot;bbb&quot;</span>
c = <span class="hljs-string">&quot;ccc&quot;</span>
pdb.set_trace()
final = a + b + c 
<span class="hljs-keyword">print</span> final

<span class="hljs-comment"># &#x300A;4 &#x5C06;&#x7A0B;&#x5E8F;&#x7EE7;&#x7EED;&#x8FD0;&#x884C;&#x300B;</span>
<span class="hljs-comment"># c-----&gt;&#x8BA9;&#x7A0B;&#x5E8F;&#x7EE7;&#x7EED;&#x5411;&#x4E0B;&#x6267;&#x884C;&#xFF0C;&#x4E0E;n&#x7684;&#x533A;&#x522B;&#x662F;n&#x53EA;&#x4F1A;&#x6267;&#x884C;&#x4E0B;&#x9762;&#x7684;&#x4E00;&#x884C;&#x4EE3;&#x7801;&#xFF0C;&#x800C;c&#x4F1A;&#x50CF;python xxxx.py&#x4E00;&#x6837; &#x7EE7;&#x7EED;&#x6267;&#x884C;&#x4E0D;&#x4F1A;&#x505C;&#x6B62;&#xFF1B;c&#x8868;&#x793A;continue&#x7684;&#x610F;&#x601D;</span>

<span class="hljs-comment"># &#x300A;5 set_trace()&#x300B;</span>
<span class="hljs-comment"># &#x5982;&#x679C;&#x7A0B;&#x5E8F;&#x4E2D;&#x6709;&#x591A;&#x4E2A;set_trace()&#xFF0C;&#x90A3;&#x4E48;&#x80FD;&#x591F;&#x8BA9;&#x7A0B;&#x5E8F;&#x5728;&#x4F7F;&#x7528;c&#x7684;&#x65F6;&#x5019;&#x505C;&#x7559;&#x5728;&#x4E0B;&#x4E00;&#x4E2A;set_trace()&#x4F4D;&#x7F6E;&#x5904;</span>
</code></pre>
<h4 id="demo-3">demo 3</h4>
<pre><code class="lang-python"><span class="hljs-comment">#coding=utf-8</span>
<span class="hljs-keyword">import</span> pdb 

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">combine</span><span class="hljs-params">(s1,s2)</span>:</span>
    s3 = s1 + s2 + s1
    s3 = <span class="hljs-string">&apos;&quot;&apos;</span> + s3 +<span class="hljs-string">&apos;&quot;&apos;</span>
    <span class="hljs-keyword">return</span> s3

a = <span class="hljs-string">&quot;aaa&quot;</span>
pdb.set_trace() 
b = <span class="hljs-string">&quot;bbb&quot;</span>
c = <span class="hljs-string">&quot;ccc&quot;</span>
final = combine(a,b)
<span class="hljs-keyword">print</span> final

<span class="hljs-comment"># &#x300A;6 &#x8BBE;&#x7F6E;&#x65AD;&#x70B9;&#x300B;</span>
<span class="hljs-comment"># b----&gt;&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;&#xFF0C;&#x5373;&#x5F53;&#x4F7F;&#x7528;c&#x7684;&#x65F6;&#x5019;&#xFF0C;c&#x53EF;&#x4EE5;&#x5728;&#x9047;&#x5230;set_trace()&#x7684;&#x65F6;&#x5019;&#x505C;&#x6B62;&#xFF0C;&#x4E5F;&#x53EF;&#x4EE5;&#x5728;&#x9047;&#x5230;&#x6807;&#x8BB0;&#x6709;&#x65AD;&#x70B9;&#x7684;&#x5730;&#x65B9;&#x505C;&#x6B62;&#xFF1B;b&#x8868;&#x793A;break&#x7684;&#x610F;&#x601D;</span>
    <span class="hljs-comment">#&#x4F8B;&#x5982;&#xFF1A;</span>
    <span class="hljs-comment">#b 11 &#x5728;&#x7B2C;11&#x884C;&#x8BBE;&#x7F6E;&#x65AD;&#x70B9;&#xFF0C;&#x6CE8;&#x610F;&#x8FD9;&#x4E2A;11&#x53EF;&#x4EE5;&#x4F7F;&#x7528;l&#x6765;&#x5F97;&#x5230;</span>
    <span class="hljs-comment"># (Pdb) l</span>
    <span class="hljs-comment">#   4          s3 = s1 + s2 + s1</span>
    <span class="hljs-comment">#   5          s3 = &apos;&quot;&apos; + s3 +&apos;&quot;&apos;</span>
    <span class="hljs-comment">#   6          return s3</span>
    <span class="hljs-comment">#   7      a = &quot;aaa&quot;</span>
    <span class="hljs-comment">#   8      pdb.set_trace()</span>
    <span class="hljs-comment">#   9  -&gt;    b = &quot;bbb&quot;</span>
    <span class="hljs-comment">#  10      c = &quot;ccc&quot;</span>
    <span class="hljs-comment">#  11      final = combine(a,b)</span>
    <span class="hljs-comment">#  12      print final</span>
    <span class="hljs-comment"># [EOF]</span>
    <span class="hljs-comment"># (Pdb) b 11</span>
    <span class="hljs-comment"># Breakpoint 1 at /Users/wangmingdong/Desktop/test3.py:11</span>
    <span class="hljs-comment"># (Pdb) c</span>
    <span class="hljs-comment"># &gt; /Users/wangmingdong/Desktop/test3.py(11)&lt;module&gt;()</span>
    <span class="hljs-comment"># -&gt; final = combine(a,b)</span>
    <span class="hljs-comment"># (Pdb) l</span>
    <span class="hljs-comment">#   6          return s3</span>
    <span class="hljs-comment">#   7      a = &quot;aaa&quot;</span>
    <span class="hljs-comment">#   8      pdb.set_trace()</span>
    <span class="hljs-comment">#   9      b = &quot;bbb&quot;</span>
    <span class="hljs-comment">#  10      c = &quot;ccc&quot;</span>
    <span class="hljs-comment">#  11 B-&gt;    final = combine(a,b)</span>
    <span class="hljs-comment">#  12      print final</span>

<span class="hljs-comment"># &#x300A;7 &#x8FDB;&#x5165;&#x51FD;&#x6570;&#x7EE7;&#x7EED;&#x8C03;&#x8BD5;&#x300B;</span>
<span class="hljs-comment"># s----&gt;&#x8FDB;&#x5165;&#x51FD;&#x6570;&#x91CC;&#x9762;&#x7EE7;&#x7EED;&#x8C03;&#x8BD5;&#xFF0C;&#x5982;&#x679C;&#x4F7F;&#x7528;n&#x8868;&#x793A;&#x628A;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x7684;&#x8C03;&#x7528;&#x5F53;&#x505A;&#x4E00;&#x6761;&#x8BED;&#x53E5;&#x6267;&#x884C;&#x8FC7;&#x53BB;&#xFF0C;&#x800C;&#x4F7F;&#x7528;s&#x7684;&#x8BDD;&#xFF0C;&#x4F1A;&#x8FDB;&#x5165;&#x5230;&#x8FD9;&#x4E2A;&#x51FD;&#x6570; &#x5E76;&#x4E14;&#x505C;&#x6B62;</span>
    <span class="hljs-comment">#&#x4F8B;&#x5982;</span>
    <span class="hljs-comment"># (Pdb) l</span>
    <span class="hljs-comment">#   6          return s3</span>
    <span class="hljs-comment">#   7      a = &quot;aaa&quot;</span>
    <span class="hljs-comment">#   8      pdb.set_trace()</span>
    <span class="hljs-comment">#   9      b = &quot;bbb&quot;</span>
    <span class="hljs-comment">#  10      c = &quot;ccc&quot;</span>
    <span class="hljs-comment">#  11 B-&gt;    final = combine(a,b)</span>
    <span class="hljs-comment">#  12      print final</span>
    <span class="hljs-comment"># [EOF]</span>
    <span class="hljs-comment"># (Pdb) s</span>
    <span class="hljs-comment"># --Call--</span>
    <span class="hljs-comment"># &gt; /Users/wangmingdong/Desktop/test3.py(3)combine()</span>
    <span class="hljs-comment"># -&gt; def combine(s1,s2):</span>
    <span class="hljs-comment"># (Pdb) l</span>
    <span class="hljs-comment">#   1      import pdb</span>
    <span class="hljs-comment">#   2</span>
    <span class="hljs-comment">#   3  -&gt;    def combine(s1,s2):</span>
    <span class="hljs-comment">#   4          s3 = s1 + s2 + s1</span>
    <span class="hljs-comment">#   5          s3 = &apos;&quot;&apos; + s3 +&apos;&quot;&apos;</span>
    <span class="hljs-comment">#   6          return s3</span>
    <span class="hljs-comment">#   7      a = &quot;aaa&quot;</span>
    <span class="hljs-comment">#   8      pdb.set_trace()</span>
    <span class="hljs-comment">#   9      b = &quot;bbb&quot;</span>
    <span class="hljs-comment">#  10      c = &quot;ccc&quot;</span>
    <span class="hljs-comment">#  11 B    final = combine(a,b)</span>
    <span class="hljs-comment"># (Pdb)</span>

<span class="hljs-comment"># &#x300A;8 &#x67E5;&#x770B;&#x4F20;&#x9012;&#x5230;&#x51FD;&#x6570;&#x4E2D;&#x7684;&#x53D8;&#x91CF;&#x300B;</span>
<span class="hljs-comment"># a----&gt;&#x8C03;&#x7528;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#x65F6;&#xFF0C;&#x53EF;&#x4EE5;&#x67E5;&#x770B;&#x4F20;&#x9012;&#x5230;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x4E2D;&#x7684;&#x6240;&#x6709;&#x7684;&#x53C2;&#x6570;&#xFF1B;a&#x8868;&#x793A;arg&#x7684;&#x610F;&#x601D;</span>
    <span class="hljs-comment">#&#x4F8B;&#x5982;&#xFF1A;</span>
    <span class="hljs-comment"># (Pdb) l</span>
    <span class="hljs-comment">#   1      #coding=utf-8</span>
    <span class="hljs-comment">#   2      import pdb</span>
    <span class="hljs-comment">#   3</span>
    <span class="hljs-comment">#   4  -&gt;    def combine(s1,s2):</span>
    <span class="hljs-comment">#   5          s3 = s1 + s2 + s1</span>
    <span class="hljs-comment">#   6          s3 = &apos;&quot;&apos; + s3 +&apos;&quot;&apos;</span>
    <span class="hljs-comment">#   7          return s3</span>
    <span class="hljs-comment">#   8</span>
    <span class="hljs-comment">#   9      a = &quot;aaa&quot;</span>
    <span class="hljs-comment">#  10      pdb.set_trace()</span>
    <span class="hljs-comment">#  11      b = &quot;bbb&quot;</span>
    <span class="hljs-comment"># (Pdb) a</span>
    <span class="hljs-comment"># s1 = aaa</span>
    <span class="hljs-comment"># s2 = bbb</span>

<span class="hljs-comment"># &#x300A;9 &#x6267;&#x884C;&#x5230;&#x51FD;&#x6570;&#x7684;&#x6700;&#x540E;&#x4E00;&#x6B65;&#x300B;</span>
<span class="hljs-comment"># r-----&gt;&#x5982;&#x679C;&#x5728;&#x51FD;&#x6570;&#x4E2D;&#x4E0D;&#x60F3;&#x4E00;&#x6B65;&#x6B65;&#x7684;&#x8C03;&#x8BD5;&#x4E86;&#xFF0C;&#x53EA;&#x662F;&#x60F3;&#x5230;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x7684;&#x6700;&#x540E;&#x4E00;&#x6761;&#x8BED;&#x53E5;&#x90A3;&#x4E2A;&#x4F4D;&#x7F6E;&#xFF0C;&#x6BD4;&#x5982;return&#x8BED;&#x53E5;&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x53EF;&#x4EE5;&#x4F7F;&#x7528;r&#xFF1B;r&#x8868;&#x793A;return&#x7684;&#x610F;&#x601D;</span>
</code></pre>
<h4 id="demo-4">demo 4</h4>
<pre><code class="lang-python">In [1]: def pdb_test(arg):
   ...:     for i in range(arg):
   ...:         print(i)
   ...:     return arg
   ...:

In [2]: #&#x5728;python&#x4EA4;&#x4E92;&#x6A21;&#x5F0F;&#x4E2D;&#xFF0C;&#x5982;&#x679C;&#x60F3;&#x8981;&#x8C03;&#x8BD5;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x90A3;&#x4E48;&#x53EF;&#x4EE5;

In [3]: #&#x91C7;&#x7528;&#xFF0C;pdb.run&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x5982;&#x4E0B;&#xFF1A;

In [4]: import pdb

In [5]: pdb.run(&quot;pdb_test(10)&quot;)
&gt; &lt;string&gt;(1)&lt;module&gt;()
(Pdb) s
--Call--
&gt; &lt;ipython-input-1-ef4d08b8cc81&gt;(1)pdb_test()
-&gt; def pdb_test(arg):
(Pdb) l
  1  -&gt;    def pdb_test(arg):
  2          for i in range(arg):
  3              print(i)
  4          return arg
[EOF]
(Pdb) n
&gt; &lt;ipython-input-1-ef4d08b8cc81&gt;(2)pdb_test()
-&gt; for i in range(arg):
(Pdb) l
  1      def pdb_test(arg):
  2  -&gt;        for i in range(arg):
  3              print(i)
  4          return arg
[EOF]
(Pdb) n
&gt; &lt;ipython-input-1-ef4d08b8cc81&gt;(3)pdb_test()
-&gt; print(i)
(Pdb)
0
&gt; &lt;ipython-input-1-ef4d08b8cc81&gt;(2)pdb_test()
-&gt; for i in range(arg):
(Pdb)
&gt; &lt;ipython-input-1-ef4d08b8cc81&gt;(3)pdb_test()
-&gt; print(i)
(Pdb)
1
&gt; &lt;ipython-input-1-ef4d08b8cc81&gt;(2)pdb_test()
-&gt; for i in range(arg):
(Pdb)
</code></pre>
<h4 id="demo-5-&#x8FD0;&#x884C;&#x8FC7;&#x7A0B;&#x4E2D;&#x4F7F;&#x7528;pdb&#x4FEE;&#x6539;&#x53D8;&#x91CF;&#x7684;&#x503C;">demo 5 &#x8FD0;&#x884C;&#x8FC7;&#x7A0B;&#x4E2D;&#x4F7F;&#x7528;pdb&#x4FEE;&#x6539;&#x53D8;&#x91CF;&#x7684;&#x503C;</h4>
<pre><code class="lang-python">In [7]: pdb.run(&quot;pdb_test(1)&quot;)
&gt; &lt;string&gt;(1)&lt;module&gt;()
(Pdb) s
--Call--
&gt; &lt;ipython-input-1-ef4d08b8cc81&gt;(1)pdb_test()
-&gt; def pdb_test(arg):
(Pdb) a
arg = 1
(Pdb) l
  1  -&gt;    def pdb_test(arg):
  2          for i in range(arg):
  3              print(i)
  4          return arg
[EOF]
(Pdb) !arg = 100  #!!!&#x8FD9;&#x91CC;&#x662F;&#x4FEE;&#x6539;&#x53D8;&#x91CF;&#x7684;&#x65B9;&#x6CD5;
(Pdb) n
&gt; &lt;ipython-input-1-ef4d08b8cc81&gt;(2)pdb_test()
-&gt; for i in range(arg):
(Pdb) l
  1      def pdb_test(arg):
  2  -&gt;        for i in range(arg):
  3              print(i)
  4          return arg
[EOF]
(Pdb) p arg
100
(Pdb)
</code></pre>
<h4 id="&#x7EC3;&#x4E00;&#x7EC3;&#x8BF7;&#x4F7F;&#x7528;&#x6240;&#x5B66;&#x7684;pdb&#x8C03;&#x8BD5;&#x6280;&#x5DE7;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x8C03;&#x8BD5;&#x51FA;bug">&#x7EC3;&#x4E00;&#x7EC3;:&#x8BF7;&#x4F7F;&#x7528;&#x6240;&#x5B66;&#x7684;pdb&#x8C03;&#x8BD5;&#x6280;&#x5DE7;&#x5BF9;&#x5176;&#x8FDB;&#x884C;&#x8C03;&#x8BD5;&#x51FA;bug</h4>
<pre><code class="lang-python"><span class="hljs-comment">#coding=utf-8</span>
<span class="hljs-keyword">import</span> pdb 

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">add3Nums</span><span class="hljs-params">(a1,a2,a3)</span>:</span>
    result = a1+a2+a3
    <span class="hljs-keyword">return</span> result


<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">get3NumsAvarage</span><span class="hljs-params">(s1,s2)</span>:</span>
    s3 = s1 + s2 + s1
    result = <span class="hljs-number">0</span>
    result = add3Nums(s1,s2,s3)/<span class="hljs-number">3</span>

<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">&apos;__main__&apos;</span>:

    a = <span class="hljs-number">11</span>
    <span class="hljs-comment"># pdb.set_trace() </span>
    b = <span class="hljs-number">12</span>
    final = get3NumsAvarage(a,b)
    <span class="hljs-keyword">print</span> final
</code></pre>
<p>pdb &#x8C03;&#x8BD5;&#x6709;&#x4E2A;&#x660E;&#x663E;&#x7684;&#x7F3A;&#x9677;&#x5C31;&#x662F;&#x5BF9;&#x4E8E;&#x591A;&#x7EBF;&#x7A0B;&#xFF0C;&#x8FDC;&#x7A0B;&#x8C03;&#x8BD5;&#x7B49;&#x652F;&#x6301;&#x5F97;&#x4E0D;&#x591F;&#x597D;&#xFF0C;&#x540C;&#x65F6;&#x6CA1;&#x6709;&#x8F83;&#x4E3A;&#x76F4;&#x89C2;&#x7684;&#x754C;&#x9762;&#x663E;&#x793A;&#xFF0C;&#x4E0D;&#x592A;&#x9002;&#x5408;&#x5927;&#x578B;&#x7684; python &#x9879;&#x76EE;&#x3002;&#x800C;&#x5728;&#x8F83;&#x5927;&#x7684; python &#x9879;&#x76EE;&#x4E2D;&#xFF0C;&#x8FD9;&#x4E9B;&#x8C03;&#x8BD5;&#x9700;&#x6C42;&#x6BD4;&#x8F83;&#x5E38;&#x89C1;&#xFF0C;&#x56E0;&#x6B64;&#x9700;&#x8981;&#x4F7F;&#x7528;&#x66F4;&#x4E3A;&#x9AD8;&#x7EA7;&#x7684;&#x8C03;&#x8BD5;&#x5DE5;&#x5177;&#x3002;</p>

                    
                    </section>
                
                
                </div>
            </div>
        </div>

        
        <a href="../03day/section.4.html" class="navigation navigation-prev " aria-label="Previous page: 模块"><i class="fa fa-angle-left"></i></a>
        
        
        <a href="../03day/section.5.html" class="navigation navigation-next " aria-label="Next page: 编码风格"><i class="fa fa-angle-right"></i></a>
        
    </div>
</div>

        
<script src="../gitbook/app.js"></script>

    
    <script src="../gitbook/plugins/gitbook-plugin-toggle-chapters/toggle.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-splitter/splitter.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-sharing/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-fontsettings/buttons.js"></script>
    

    
    <script src="../gitbook/plugins/gitbook-plugin-livereload/plugin.js"></script>
    

<script>
require(["gitbook"], function(gitbook) {
    var config = {"toggle-chapters":{},"splitter":{},"emphasize":{},"highlight":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"livereload":{}};
    gitbook.start(config);
});
</script>

        <!-- body:end -->
    </body>
    <!-- End of book python基础语言 -->
</html>
